<template>
  <div class="common-layout">
    <el-container class="main-container">
      <el-header class="main-header">
        <div class="header-left">
          <h2>智慧农业管理系统</h2>
        </div>
        <div class="header-right">
          <el-dropdown>
            <span class="user-info">
              <el-icon><user /></el-icon>
              管理员
              <el-icon><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <el-dropdown-item divided @click="handleLogout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <el-container>
        <el-aside width="220px" class="main-aside">
          <el-menu
            router
            :default-active="$route.path"
            class="el-menu-vertical"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-menu-item index="/home">
              <el-icon><HomeFilled /></el-icon>
              <span>主页</span>
            </el-menu-item>
            
            <el-sub-menu index="1">
              <template #title>
                <el-icon><user /></el-icon>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/user">用户列表</el-menu-item>
              <!-- <el-menu-item index="/user-roles">角色权限</el-menu-item> -->
            </el-sub-menu>
            
            <el-sub-menu index="2">
              <template #title>
                <el-icon><location /></el-icon>
                <span>农场管理</span>
              </template>
              <el-menu-item index="/secondkill">秒杀列表</el-menu-item>
              <el-menu-item index="/land">土地管理</el-menu-item>
              <!-- <el-menu-item index="/plot-map">地块地图</el-menu-item> -->
            </el-sub-menu>
            
            <el-sub-menu index="3">
              <template #title>
                <el-icon><goods /></el-icon>
                <span>文件管理</span>
              </template>
              <el-menu-item index="/file">上传文件</el-menu-item>
              <el-menu-item index="/package-stats">下载文件</el-menu-item>
            </el-sub-menu>
            
            <!-- <el-sub-menu index="4">
              <template #title>
                <el-icon><document /></el-icon>
                <span>租赁管理</span>
              </template>
              <el-menu-item index="/rental-list">租赁列表</el-menu-item>
              <el-menu-item index="/rental-stats">租赁统计</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="5">
              <template #title>
                <el-icon><icon-menu /></el-icon>
                <span>作物管理</span>
              </template>
              <el-menu-item index="/crop-list">作物列表</el-menu-item>
              <el-menu-item index="/harvest-list">收获记录</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="6">
              <template #title>
                <el-icon><setting /></el-icon>
                <span>设备管理</span>
              </template>
              <el-menu-item index="/sensor-list">传感器列表</el-menu-item>
              <el-menu-item index="/sensor-data">传感器数据</el-menu-item>
              <el-menu-item index="/remote-control">远程控制</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="7">
              <template #title>
                <el-icon><goods /></el-icon>
                <span>农资管理</span>
              </template>
              <el-menu-item index="/supply-list">农资列表</el-menu-item>
              <el-menu-item index="/supply-usage">使用记录</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="8">
              <template #title>
                <el-icon><goods /></el-icon>
                <span>订单管理</span>
              </template>
              <el-menu-item index="/order-list">订单列表</el-menu-item>
              <el-menu-item index="/payment-list">支付记录</el-menu-item>
              <el-menu-item index="/order-stats">订单统计</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="9">
              <template #title>
                <el-icon><goods /></el-icon>
                <span>商品管理</span>
              </template>
              <el-menu-item index="/product-list">商品列表</el-menu-item>
              <el-menu-item index="/product-stats">销售统计</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="10">
              <template #title>
                <el-icon><document /></el-icon>
                <span>任务管理</span>
              </template>
              <el-menu-item index="/task-list">任务列表</el-menu-item>
              <el-menu-item index="/task-assign">分配任务</el-menu-item>
              <el-menu-item index="/task-result">任务结果</el-menu-item>
            </el-sub-menu>
            
            <el-sub-menu index="11">
              <template #title>
                <el-icon><document /></el-icon>
                <span>系统管理</span>
              </template>
              <el-menu-item index="/operation-log">操作日志</el-menu-item>
              <el-menu-item index="/system-settings">系统设置</el-menu-item>
              <el-menu-item index="/data-backup">数据备份</el-menu-item>
            </el-sub-menu> -->
          </el-menu>
        </el-aside>
        
        <el-main class="main-content">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { Location, Menu as IconMenu, Document, Setting, User, Goods, Order, Grid, Search, ArrowDown, Monitor, HomeFilled } from '@element-plus/icons-vue';

export default {
  name: 'MainView',
  components: {
    Location,
    IconMenu,
    Document,
    Setting,
    User,
    Goods,
    Order,
    ArrowDown,
    Monitor,
    HomeFilled
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleLogout() {
      this.$router.push('/login');
    }
  }
}
</script>

<style scoped>
.main-container {
  height: 100vh;
}

.main-header {
  background-color: #409EFF;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  line-height: 60px;
}

.header-left h2 {
  margin: 0;
  font-size: 20px;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  cursor: pointer;
}

.main-aside {
  background-color: #fff;
  border-right: 1px solid #e6e6e6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}

.el-menu-vertical {
  border-right: none;
}

.main-content {
  background-color: #f5f7fa;
  padding: 20px;
}

:deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
}

:deep(.el-sub-menu__title) {
  height: 50px;
  line-height: 50px;
}

:deep(.el-dropdown-menu__item) {
  padding: 8px 20px;
}
</style>